package scene;

import input.InputManager;

import java.util.ArrayList;

import main.Core;
import model.ImageSprite;
import dao.ContentManager;
import data.Vector2;
import entity.map.Camera;
import entity.map.Map;
import entity.map.MapObject;
import graphics.SpriteBatch;

public class MapScene extends BaseScene {

	ArrayList<MapObject> mapObjects;
	Map map;
	Camera camera;
	
	public MapScene(Core core) {
		super(core);
		mapObjects = new ArrayList<MapObject>();
		
		map = ContentManager.loadMap("Grasslands");
		camera = new Camera(Vector2.zero(), map.getTileSize(), new Vector2(10, 10));
		
		ImageSprite mapSprite = map.getMapSprite(this, core);
		
		MapObject mapObject = new MapObject(mapSprite, new Vector2(20f), mapSprite.getSize());
		mapObjects.add(mapObject);
	}
	
	public void update(float elapsedTime)
	{		
		camera.changePosition(Vector2.mult(InputManager.keyboard.getDirection(), 800 * elapsedTime));
		
		//camera.setPosition(Vector2.add(camera.getPosition(), new Vector2(elapsedTime * 30)));
		super.update(elapsedTime);
	}

	@Override
	public void draw(SpriteBatch spriteBatch)
	{
		for (MapObject mapObject : mapObjects) {
			mapObject.updatePosition(camera);
			if (mapObject.getSprite().isVisible())
				spriteBatch.Draw(mapObject.getSprite());
		}
	}
}
